﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JKF.BusinessLayer.BLL;
using JKF.Substructure;

namespace JKF.Web.SMS
{
    public partial class Sms_Select_Mobile : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #region Builder
        private StringBuilder optionBuilder = new StringBuilder();
        private bllSMS_TEMPLEATE SmsTemplateMgr = new bllSMS_TEMPLEATE();
        private bllSMS_CONDITION SmsConditionMgr = new bllSMS_CONDITION();
        private bllSMS_ACCOUNT SmsAccountMgr = new bllSMS_ACCOUNT();
        private bllSHOP ShopMgr = new bllSHOP();
        #endregion

        #region Options
        /// <summary>
        /// 省份
        /// </summary>
        public string Province
        {
            get
            {
                var bllArea = new bllDIC_AREA();
                return bllArea.GetArea();
            }
        }

        /// <summary>
        /// 顾客级别
        /// </summary>
        public string CustomerLevel
        {
            get
            {
                var bllLevel = new bllDIC_LEVEL();
                var levels = bllLevel.GetModelList("");
                optionBuilder.Clear();
                foreach (var level in levels)
                {
                    optionBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", level.LEVEL_CODE, Server.HtmlEncode(level.NAME));
                }
                return optionBuilder.ToString();
            }
        }

        /// <summary>
        /// Load SmsTemplate user can view
        /// </summary>
        public string SmsTemplates
        {
            get
            {
                optionBuilder.Clear();
                var availableTemplates = SmsTemplateMgr.GetListArray(
                    string.Format(
                        "STATUS='1' AND (IS_SHARE='1' OR SHOP_CODE IN(SELECT SHOP_CODE FROM SYS_USER_SHOP WHERE USER_KEY='{0}'))",
                        bllSYS_USER.CurrentUser.USER_KEY)
                    );

                foreach (var templeatEinfo in availableTemplates)
                {
                    optionBuilder.AppendFormat("<option value=\"{0}\" cont=\"{2}\">{1}</option>",
                        templeatEinfo.ID,
                        Server.HtmlEncode(templeatEinfo.TEMPLEATE_NAME),
                        Server.HtmlEncode(templeatEinfo.CONTENT).Replace("\"", "‘")
                    );
                }
                return optionBuilder.ToString();
            }
        }

        /// <summary>
        /// 短信条件
        /// </summary>
        public string SmsCondition
        {
            get
            {
                optionBuilder.Clear();
                var conditions = SmsConditionMgr.GetListArray("");
                foreach (var condit in conditions)
                {
                    optionBuilder.AppendFormat("<option value=\"{0}\">{1}</option>",
                        condit.CONDITION_KEY,
                        Server.HtmlEncode(condit.NAME)
                    );
                }
                return optionBuilder.ToString();
            }
        }

        /// <summary>
        /// 当前账户信息
        /// </summary>
        public string CurrentAccount
        {
            get
            {
                var accList = SmsAccountMgr.GetListArray(
                    string.Format(" SHOP_CODE='{0}'",
                    bllSYS_USER.CurrentUser.SHOP_CODE));
                if (accList.Count <= 0)
                {
                    return "null";
                }
                else
                {
                    accList[0].SMS_PWD = "";
                    return accList[0].ToJson();
                }
            }
        }

        /// <summary>
        /// 管理店铺
        /// </summary>
        public string ShopCheckBoxs
        {
            get
            {
                optionBuilder.Clear();
                var shops = ShopMgr.GetListArray(string.Format(" shop_code in (select shop_code from sys_user_shop where user_key='{0}')", bllSYS_USER.CurrentUser.USER_KEY));
                foreach (var shop in shops)
                {
                    optionBuilder.AppendFormat("<label><input type=\"checkbox\" value=\"{0}\"/>{1}</label>", shop.SHOP_CODE, shop.SHOP_NAME);
                }
                return optionBuilder.ToString();
            }
        }

        public string CustomerMemoDay
        {
            get
            {
                optionBuilder.Clear();
                var memType = bllCUSTOMER_MEMORIALDAY.GetMemoryDayNames();
                foreach (var shop in memType)
                {
                    optionBuilder.AppendFormat("<option value=\"{0}\">{0}</option>", Server.HtmlEncode(shop));
                }
                return optionBuilder.ToString();
            }
        }
        #endregion
    }
}